package network

import (
	"fmt"
	"github.com/spf13/cobra"
)

func GetNetworkRemoveCmd() *cobra.Command {
	return &cobra.Command{
		Use:   "remove name",
		Short: "remove the network",
		Long:  `remove specific network and drive of the network`,
		Args:  cobra.MinimumNArgs(1),
		Run:   networkRemoveHandle,
	}
}

func networkRemoveHandle(cmd *cobra.Command, args []string) {
	if len(args) < 1 {
		_ = cmd.Help()
	} else {
		if err := Init(); err != nil {
			fmt.Println("failed to init network module :", err.Error())
			return
		}
		err := deleteNetwork(args[0])
		if err != nil {
			fmt.Println("failed to remove network : ", err.Error())
		} else {
			fmt.Printf("the %s has been removed\n", args[0])
		}
	}
}
